package com.yxj04;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class StringDemo {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "中国";
        //编码
        //byte[] getBytes()：使用平台的默认字符集将该String编码为一系列字节，将结果存储到新的字节数组中
        //byte[] bys = s.getBytes();//[-28, -72, -83, -27, -101, -67]
        //byte[] bys = s.getBytes("UTF-8");//[-28, -72, -83, -27, -101, -67]
        byte[] bys = s.getBytes("GBK");//[-42, -48, -71, -6]

        //解码
        //System.out.println(Arrays.toString(bys));
        //String(byte[] bytes)：通过使用平台的默认字符集解码指定的字节数组来构造新的String
        //String ss = new String(bys,"UTF-8");
        String ss = new String(bys,"GBK");

        System.out.println(ss);
    }
}
